import VueRouter from 'vue-router';
import store from '../store';
import Vue from 'vue'
// 路由匹
Vue.use(VueRouter);
const router =  new VueRouter({
  mode: "hash",
	routes: [
        {
            path:"/",
            name:"index",
            redirect:"/login"
        },
		{
			path:"/login",
            name:"login",
            meta:{title: '登录'},
			component: () => import(/* webpackChunkName: "login" */ "@/views/login/index.vue")
        },
        {
            path:"/mapDispatch",
            name:"mapDispatch",
            meta:{title: '地图调度'},
            component: () => import(/* webpackChunkName: "mapDispatch" */ "@/views/mapDispatch/index.vue") 
        },
        {
            path:"/edit",
            name:"edit",
            meta:{title: '设置'},
            component: () => import(/* webpackChunkName: "edit" */ "@/views/edit/index.vue") 
        },
	]
});
const whiteList = [];//白名单

router.beforeEach((to, from, next) => {
    let isLogin = store.state.token
    if (!isLogin&&whiteList.indexOf(to.path) !== -1) {
        next({path: "/login"})
    } else {
        next();
    }
});
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
  }
export default router